const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
const rules = require('./webpack/rule')
const CopyPlugin = require('copy-webpack-plugin')
// const ExtractTextPlugin = require('extract-text-webpack-plugin')
module.exports = {
    mode: 'production',
    resolve: {
        alias: {
            '@': path.join(__dirname, 'src')
        },
        extensions: ['.json', '.js', '.jsx', '.ts', '.tsx'],
        modules: ["node_modules"]
    },
    entry: {
        index: path.join(__dirname, "src/web/index.ts"),
    },
    devtool: 'source-map',
    target: 'web',
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'js/[name].js',
        publicPath: './',
        chunkFilename: 'js/[name].[hash].js'
    },
    module: {
        rules
    },
    optimization: {
        splitChunks: {
            cacheGroups: {
                vendors: {
                    name: 'chunk-vendors',
                    test: /[\\/]node_modules[\\/]/,
                    priority: -10,
                    chunks: 'initial'
                },
                common: {
                    name: 'chunk-common',
                    minChunks: 2,
                    priority: -20,
                    chunks: 'initial',
                    reuseExistingChunk: true
                }
            }
        }
    },
    plugins: [
        new CaseSensitivePathsPlugin(),
        new HtmlWebpackPlugin({
            template: 'public/index.html',
            filename: 'index.html'
        }),
        new CopyPlugin({
            patterns: [{
                from: 'public',
            }
            ]
        })
    ]
}